﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Cors;

namespace API
{
    public static class WebApiConfig
    {
        public static string UrlPrefix { get { return "api"; } }

        /// <summary>
        /// 配合Gloabl.cs项目启动时默认调用
        /// </summary>
        public static string UrlPrefixRelative { get { return "~/api"; } }

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            //config.EnableCors(new EnableCorsAttribute("*", "*", "*"));

            // Web API routes
            config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{action}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            //设置路由获取调转方式
            config.Routes.MapHttpRoute(
                  name: "DefaultApi",
                  routeTemplate: WebApiConfig.UrlPrefix + "/{controller}/{action}/{id}",
                  defaults: new { id = RouteParameter.Optional }
            );
        }

    }
}
